package com.edu.exam.entity.assessment.scheme;

import com.edu.exam.enums.assessment.StandardType;
import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 考核标准实体类
 * 所属模块：B-04 考核方案管理模块
 * 对应数据库表：assessment_scheme_standard
 *
 * <p>考核标准是考核评价的具体准则和要求，包括评分标准、等级标准、及格标准等，
 * 是考核结果评价的依据。支持分数验证和等级计算功能，可与考核项目或整个方案关联。</p>
 *
 * @author 系统生成
 * @version 2.0
 * @since 2025-11-09
 */
@Entity
@Table(name = "assessment_scheme_standard")
@Data
@EqualsAndHashCode(callSuper = false)
@EntityListeners(AuditingEntityListener.class)
public class AssessmentSchemeStandard {

    /**
     * 主键ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 关联方案ID
     */
    @Column(name = "scheme_id", nullable = false)
    private Long schemeId;

    /**
     * 关联项目ID（可为空表示方案级标准）
     */
    @Column(name = "item_id")
    private Long itemId;

    /**
     * 标准类型
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "type", nullable = false, length = 20)
    private StandardType type;

    /**
     * 标准内容
     */
    @Column(name = "content", nullable = false, columnDefinition = "TEXT")
    private String content;

    /**
     * 及格分数
     */
    @Column(name = "pass_score", precision = 5, scale = 2)
    private BigDecimal passScore;

    /**
     * 等级
     */
    @Column(name = "grade_level", length = 10)
    private String gradeLevel;

    /**
     * 最低分数
     */
    @Column(name = "min_score")
    private Integer minScore;

    /**
     * 最高分数
     */
    @Column(name = "max_score")
    private Integer maxScore;

    /**
     * 优秀分数线
     */
    @Column(name = "excellent_score", precision = 5, scale = 2)
    private BigDecimal excellentScore;

    /**
     * 良好分数线
     */
    @Column(name = "good_score", precision = 5, scale = 2)
    private BigDecimal goodScore;

    /**
     * 中等分数线
     */
    @Column(name = "medium_score", precision = 5, scale = 2)
    private BigDecimal mediumScore;

    /**
     * 及格分数线
     */
    @Column(name = "passing_score", precision = 5, scale = 2)
    private BigDecimal passingScore;

    /**
     * 评分标准
     */
    @Column(name = "scoring_criteria", columnDefinition = "TEXT")
    private String scoringCriteria;

    /**
     * 等级描述
     */
    @Column(name = "grade_description", columnDefinition = "TEXT")
    private String gradeDescription;

    /**
     * 标准说明
     */
    @Column(name = "standard_explanation", columnDefinition = "TEXT")
    private String standardExplanation;

    /**
     * 适用范围
     */
    @Column(name = "applicable_scope", length = 200)
    private String applicableScope;

    /**
     * 创建时间
     */
    @CreatedDate
    @Column(name = "create_time", nullable = false, updatable = false)
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @LastModifiedDate
    @Column(name = "update_time", nullable = false)
    private LocalDateTime updateTime;

    /**
     * 是否删除
     */
    @Column(name = "is_deleted", nullable = false)
    private Boolean isDeleted = false;

    /**
     * 删除时间
     */
    @Column(name = "deleted_time")
    private LocalDateTime deletedTime;

    /**
     * 删除人ID
     */
    @Column(name = "deleted_by")
    private Long deletedBy;

    // ===== 关联对象 =====

    /**
     * 所属考核方案
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "scheme_id", insertable = false, updatable = false)
    private AssessmentSchemeManagement scheme;

    /**
     * 所属考核项目（可为空）
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "item_id", insertable = false, updatable = false)
    private AssessmentSchemeItem item;

}